# Contributor/Maintainer: Sarah Ottinger <schalaalexiazeal@gmail.com>

_realname=wwrando
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=1.10.0
pkgrel=1
pkgdesc="Wind Waker Randomizer (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32')
url="https://github.com/LagoLunatic/wwrando"
license=('spdx:MIT')
depends=(
  "${MINGW_PACKAGE_PREFIX}-python"
  "${MINGW_PACKAGE_PREFIX}-pyside2"
  "${MINGW_PACKAGE_PREFIX}-python-yaml"
  "${MINGW_PACKAGE_PREFIX}-python-pillow"
)
makedepends=(
  "${MINGW_PACKAGE_PREFIX}-pyside2-tools"
)
optdepends=(
  "${MINGW_PACKAGE_PREFIX}-python-tinyaes"
  "${MINGW_PACKAGE_PREFIX}-python-pyfastbti"
  "${MINGW_PACKAGE_PREFIX}-python-pyfasttextureutils"
)
options=('staticlibs' 'strip' '!debug')
source=("https://github.com/LagoLunatic/wwrando/archive/refs/tags/$pkgver.tar.gz")
sha256sums=('9d05501ff5468aa5d790cb10c7daaed50700f81b7254bc9cdbfe3c3f28c50d19')

prepare() {
  cd "${srcdir}"

  rm -rf python-build-${CARCH} | true
  cp -r "${_realname}-${pkgver}" "python-build-${CARCH}"
}

build() {
  msg "Python build for ${CARCH}"
  cd "${srcdir}/python-build-${CARCH}"
  ${MINGW_PREFIX}/bin/python -m compileall .
}

package() {
  cd "${srcdir}/python-build-${CARCH}"
  local _pyver=$(${MINGW_PREFIX}/bin/python -c "import sys;sys.stdout.write('.'.join(map(str, sys.version_info[:2])))")
  find . -type f -exec install -Dm644 {} "${pkgdir}${MINGW_PREFIX}/lib/python${_pyver}/site-packages/wwrando/"{} \;

  mkdir -p "${pkgdir}${MINGW_PREFIX}/bin"
  printf "#!/bin/sh\npython ${MINGW_PREFIX}/lib/python${_pyver}/site-packages/wwrando/wwrando.py \$@\n" >> "${pkgdir}${MINGW_PREFIX}/bin/wwrando"
  chmod +x "${pkgdir}${MINGW_PREFIX}/bin/wwrando"
  install -Dm644 LICENSE.txt "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE.txt"
}
